<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>交易列表导出 - 管理后台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        body {
            min-height: 100vh;
            background: linear-gradient(135deg, #e0e7ff 0%, #f5f7fa 100%);
            font-family: 'Segoe UI', 'Microsoft YaHei', Arial, sans-serif;
            margin: 0;
        }

        .content-area {
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            padding: 40px 0;
        }

        .card {
            background: #fff;
            border-radius: 16px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.10);
            padding: 40px 36px 32px 36px;
            max-width: 420px;
            width: 100%;
        }

        .section-title {
            font-size: 22px;
            color: #1a3a6c;
            margin-bottom: 28px;
            padding-bottom: 12px;
            border-bottom: 2px solid #1a3a6c;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .section-title i {
            color: #007bff;
            font-size: 22px;
        }

        .btn-primary {
            width: 100%;
            padding: 15px;
            border-radius: 8px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            border: none;
            background: #1a3a6c;
            color: #fff;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            box-shadow: 0 2px 8px rgba(26, 58, 108, 0.10);
            margin-top: 18px;
        }

        .btn-primary:hover {
            background: #15315a;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(26, 58, 108, 0.18);
        }

        .result-card {
            margin-top: 24px;
            background: #f8f9fa;
            border-left: 4px solid #1a3a6c;
            border-radius: 8px;
            padding: 18px 20px;
            font-size: 15px;
            color: #1a3a6c;
            box-shadow: 0 2px 8px rgba(26, 58, 108, 0.06);
            display: none;
            align-items: center;
            gap: 10px;
        }

        .result-card.success {
            border-left-color: #2ecc71;
            color: #2ecc71;
        }

        .result-card.error {
            border-left-color: #e74c3c;
            color: #e74c3c;
        }

        .result-card i {
            font-size: 18px;
        }
    </style>
</head>
<body>
    <div class="content-area">
        <div class="card">
            <div class="section-title">
                <i class="fa fa-file-csv"></i>交易列表导出
            </div>

            <button class="btn-primary" onclick="downloadTradeCSV()">
                <i class="fa fa-download"></i>导出CSV
            </button>

            <div class="result-card" id="trade-csv-result">
                <i class="fa"></i>
                <span id="trade-csv-result-text"></span>
            </div>
        </div>
    </div>

    <script>
        function downloadTradeCSV() {
            fetch('http://localhost:8080/admin/trade/toCSV')
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应异常');
                    }
                    return response.blob();
                })
                .then(blob => {
                    const url = window.URL.createObjectURL(blob);
                    const a = document.createElement('a');
                    a.href = url;
                    a.download = 'trade.csv';
                    document.body.appendChild(a);
                    a.click();
                    document.body.removeChild(a);
                    window.URL.revokeObjectURL(url);

                    showCSVResult({
                        code: '200',
                        message: '下载完成'
                    });
                })
                .catch(error => {
                    showCSVResult({
                        code: 'error',
                        message: error.toString()
                    });
                });
        }

        function showCSVResult(result) {
            const card = document.getElementById('trade-csv-result');
            const textElement = document.getElementById('trade-csv-result-text');
            const iconElement = card.querySelector('i');

            if (result.code === '200') {
                card.className = 'result-card success';
                iconElement.className = 'fa fa-check-circle';
                textElement.textContent = result.message || '下载完成';
            } else {
                card.className = 'result-card error';
                iconElement.className = 'fa fa-times-circle';
                textElement.textContent = result.message || '导出失败';
            }

            card.style.display = 'flex';

            // 5秒后自动隐藏结果提示
            setTimeout(() => {
                card.style.display = 'none';
            }, 5000);
        }
    </script>
</body>
</html>